import java.util.Arrays;

/**
 * 1465. 切割后面积最大的蛋糕
 */
public class No1465 {
    private final int MOD = (int) (1e9 + 7);

    public int maxArea(int h, int w, int[] horizontalCuts, int[] verticalCuts) {
        Arrays.sort(horizontalCuts);
        Arrays.sort(verticalCuts);
        int m = horizontalCuts.length;
        int n = verticalCuts.length;
        int maxH = Math.max(horizontalCuts[0], h - horizontalCuts[m - 1]);
        int maxW = Math.max(verticalCuts[0], w - verticalCuts[n - 1]);

        for (int i = 1; i < m; i++) {
            maxH = Math.max(horizontalCuts[i] - horizontalCuts[i - 1], maxH);
        }
        for (int i = 1; i < n; i++) {
            maxW = Math.max(verticalCuts[i] - verticalCuts[i - 1], maxW);
        }

        return (int) ((long) maxH * maxW % MOD);
    }
}
